package com.examples.control;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;

public class ControlBasic {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Display display = Display.getDefault();
	    Shell shell = new Shell(display);
	    
	    GridLayout layout = new GridLayout(2, false);
	    
	    shell.setLayout(layout);
	    shell.setText("Practise");
	    
	    Label label = new Label(shell, SWT.NONE);
	    label.setText("A label");
	    
	    Button button = new Button(shell, SWT.PUSH);
	    button.setText("Press Me");
	    
	    label = new Label(shell, SWT.BORDER);
	    label.setText("This is a label");
	    
	    GridData data = new GridData(GridData.FILL, GridData.BEGINNING, true, false, 2, 1);
	    label.setLayoutData(data);
	    
	    
	    label = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
	    
	    data = new GridData(GridData.FILL, GridData.BEGINNING, true, false, 2, 1);
	    data.horizontalSpan=2;
	    label.setLayoutData(data);
	    
	    Button b = new Button(shell, SWT.PUSH);
	    b.setText("New Button");
	    data = new GridData(GridData.END, GridData.BEGINNING, false,false, 2, 1);
	    b.setLayoutData(data);

	    Spinner spinner = new Spinner(shell, SWT.READ_ONLY);
	    spinner.setMinimum(0);
	    spinner.setMaximum(1000);
	    spinner.setSelection(500);
	    spinner.setIncrement(1);
	    spinner.setPageIncrement(100);
	    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
	    gridData.widthHint = SWT.DEFAULT;
	    gridData.heightHint = SWT.DEFAULT;
	    gridData.horizontalSpan=2;
	    spinner.setLayoutData(gridData);
	    
	    Canvas canvas = new Canvas(shell, SWT.NONE);
		gridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1);
	    canvas.setLayoutData(gridData);
	    canvas.addListener(SWT.MouseMove, new Listener() {
			
			@Override
			public void handleEvent(Event event) {
				System.out.println("Mouse Moved over");
				
			}
		});
	    canvas.setBackground(new Color(display, 0, 240, 255));
	    
	    Combo combo = new Combo(shell, SWT.NONE);
	    gridData = new GridData(SWT.END,SWT.BEGINNING,true,true,5,1);
	    combo.setLayoutData(gridData);
	    combo.setVisibleItemCount(5);
	    combo.setItems(new String[]{"1","2","3","4","5","6"});
	    combo.setText("Choose a value");
	        
	    
	    Composite composite = new Composite(shell, SWT.BORDER);
	    gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
	    gridData.horizontalSpan= 2;
	    composite.setLayoutData(gridData);
	    composite.setLayout(new GridLayout(1, false));
	    
	    Text text = new Text(composite, SWT.NONE);
	    text.setText("Testing");
	    gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
	    text.setLayoutData(gridData);
	    
	    text = new Text(composite, SWT.NONE);
	    text.setText("Another test");
	    Group group = new Group(shell, SWT.NONE);
	    group.setText("This is my group");
	    gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
	    gridData.horizontalSpan= 2;
	    group.setLayoutData(gridData);
	    group.setLayout(new RowLayout(SWT.VERTICAL));
	    text = new Text(group, SWT.NONE);
	    text.setText("Another test");
	    
	    shell.pack();
	    shell.open();
	    while (!shell.isDisposed()) {
	      if (!display.readAndDispatch())
	        display.sleep();
	    }

	  //display.dispose(); //Commented only for SWTShowcase application.

	}
}
